<?
namespace Site\Event
{
    class   GetSubpage extends \Api\AjaxEvent\Listener
    {
        /**
         * Zdarzenie ładuje wskazaną podstronę do zmiennej
         * typu smarty w załadowanym widoku.
         * 
         * @return status + wiadomość
         */
         public function __event__GetSubpage()
         {  
                      
            $alias = $this->m_param['alias'];
            $html = array();
            $result = false;
            $view = new \Api\View\Content(array(), \Api\Config::$param);
            $html['alias']=$alias;
                                     
            if($alias == 'intro')
            {            
                // sklonowa c smarty                                
                $html['content'] = $view->fetchTmp('index');
                $html['title']='';
                
                $result = true;                
            }else
            {
               
                
                $psub = new \Site\Model\Subpage($this->m_config);
                if(($sub = $psub->GetByAlias($alias)) !== false)
                {
  
                    $result = true;                                
                    $view->content = $sub;                     
                    $html['content'] = $view->fetchTmp($sub['view_template']);                    
                    $html['title'] = $sub['title'];
                    $html['background']=$sub['background'];
                    $html['animation']=array('action'=>$sub['action'], 
                        'direction'=>$sub['direction']);
                }               
                
            }
                                    
            return json_encode(array(
                'result'=>$result,
                'data'=>$html                                            
            ));          
         }
         
    }
}
?>